<?php

use Hyperf\Collection\Arr;
use Hyperf\Stringable\Str;
use function Hyperf\Support\now;

/**
 * random
 * @param int $number
 * @param int $num
 * @param string $str
 * @return string
 */
function random(int $number = 6, int $num = 0, string $str = ''): string
{
    if ($num === 0) return Str::random($number);
    for ($i = 0; $i < $number; $i++) $str .= Arr::random(range(0, 9));
    return $str;
}

/**
 * success
 * @param mixed $data
 * @param string $msg
 * @return array
 */
function success(mixed $data = [], string $msg = 'success'): array
{
    return [
        'code' => 200,
        'msg' => $msg,
        'data' => $data,
        'timestamp' => now()->format('Y-m-d H:i:s.u'),
    ];
}